import java.util.ArrayList;
import java.util.List;
import java.util.Random;
 class Poker {
    private int rank;//扑克牌的排行
    private String suit;//扑克牌的花色

    public Poker(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "Poker{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }
}

public class TestDemo {
        //买牌
    public static final String Suit[]={"♠", "♥", "♣", "♦"};

    public static void buyPoker(List<Poker> pokerList) {
         //首先产生1-13个数字，然后每一个数字对应着四种花色
         for(int i =1;i<=13;++i) {
             for(int j=0;j<4;++j) {
                 Poker poker = new Poker(i,Suit[j]);
                 pokerList.add(poker);
             }
         }
    }

    public static void SwapPoker(List<Poker>pokerList,int i,int index) {
             //得到i下标的牌，
        Poker tmp = pokerList.get(i);
        //将i下标的位置设置为index下表的牌
        pokerList.set(i,pokerList.get(index));
        //再把i下标这个牌放到index的位置上去
        pokerList.set(index,tmp);
    }
    private static List<Poker> shuffle(List<Poker> pokerList) {
        //主要是将买好的牌进行打乱
        for(int i = pokerList.size()-1;i>0;--i) {
            //产生随机数
            Random random = new Random();
            int index = random.nextInt(i);
            //得到这个随机位置的牌
            SwapPoker(pokerList,i,index);
        }
        return pokerList;
    }
    public static void main(String[] args) {
       //实现一副扑克牌
        List<Poker> pokerList = new ArrayList<>();
        buyPoker(pokerList);//已经买好的牌
        System.out.println(pokerList);
        List<Poker> pokers =shuffle(pokerList);//洗过的牌
        System.out.println(pokers);
        //接下来三人开始斗地主
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        List<List<Poker>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        //接下来开始轮流发牌，每个人只有5张牌，一共法给3个人
        for(int i=0;i<5;++i) {
            for(int j =0;j<3;++j) {
                //先从桌子上摸一张牌，然后给一个人
                Poker card = pokers.remove(0);
                hands.get(j).add(i,card);
            }
        }
        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println(hand3);
    }
}
